package com.sctu.edu.tracks;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;

import com.sctu.edu.tracks.fragment.Fragment1;
import com.sctu.edu.tracks.fragment.Fragment2;


public class MainActivity extends FragmentActivity {

    private Fragment fragment1, fragment2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fragment1 = new Fragment1();
        fragment2 = new Fragment2();

        //默认加载第一个fragment
        FragmentTransaction fragmentTransaction =  getSupportFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.main_fragment,fragment1);
        fragmentTransaction.commit();
    }

    public void click(View view) {
        int id = view.getId();
        FragmentTransaction fragmentTransaction =  getSupportFragmentManager().beginTransaction();

        switch (id) {
            case R.id.btn1:
                Log.e("xxx", "btn1");
                fragmentTransaction.replace(R.id.main_fragment, fragment1);
                fragmentTransaction.commit();
                break;
            case R.id.btn2:
                Log.e("xxx", "btn2");
                fragmentTransaction.replace(R.id.main_fragment, fragment2);
                fragmentTransaction.commit();
                break;
            default:
                break;
        }
    }
}
